// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import Router from 'vue-router';
import App from './App'
import router from './router'
import  { LoadingPlugin, ToastPlugin } from 'vux'

require('es6-promise').polyfill();
require('../static/css/iconfont.css')

Vue.config.productionTip = false
Vue.use(Router);
Vue.use(ToastPlugin)
Vue.use(LoadingPlugin);

	mui.plusReady(function() {
		var _toast = null;
		//获取推送的clientID
		var clientId = plus.push.getClientInfo().clientid;
		localStorage.setItem('clientId',clientId);

		// 监听点击消息事件
	    plus.push.addEventListener("click",function(msg){
	    	router.push('/pushInfoList');

	        // 判断是从本地创建还是离线推送的消息
	        switch( msg.payload ) {
	            case "LocalMSG":
	                outSet( "点击本地创建消息启动：" );
	            break;
	            default:
	                outSet( "点击离线推送消息启动：");
	            break;
	        }
	        // 提示点击的内容
	        plus.ui.alert( msg.content );
	        // 处理其它数据
	        logoutPushMsg( msg );
	    }, false );
	    // 监听在线消息事件
	    plus.push.addEventListener("receive",function(msg){
	    	var result = localStorage.getItem('result');
	    	if(result){
	    		router.push('/pushInfoList');
	    	}
	        logoutPushMsg( msg );
	    }, false );

		mui.back = function() {
			if(router.match(location).hash == '#/pushInfoList'){
				router.push('/index');
			}else if(router.match(location).hash == '#/' || router.match(location).hash == '#/index' || router.match(location).name == '#/workManagement' || router.match(location).name == '#/runThePartyStrictly' || router.match(location).name == '#/mine' ){
				var result = confirm("你确定要退出吗？");
				if(result == true){
					localStorage.removeItem("result");
					localStorage.removeItem("userRealName");
					localStorage.removeItem('checked');
					plus.runtime.quit();
				}
			}else{
				router.go(-1);
			}
		}
	})	

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  template: '<App/>',
  components: { App }
})

